<template>
<div class="info-issue">
  <el-dialog
    title="任务下发"
    width = "30%"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading"
             label-width="120px">
      <el-row :gutter="15">
        <el-col :span="20">
            <el-form-item label="选择任务" prop="taskId"
                :rules="[
                   {required: true, message:'请选择需要下发的任务', trigger:'blur'}
                 ]">
                <el-select style="width: 100%;" v-model="inputForm.taskId" placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.id"
                    :label="item.name+'|'+item.resolution"
                    :value="item.id">
                  </el-option>
                </el-select>
           </el-form-item>
           <div style="padding-left: 52px;">将任务下发到设备后，设备将自动下载更新此任务</div>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        options: [],
        value: '',
        visible: false,
        loading: false,
        inputForm: {
          devId: '',
          taskId: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, ids) {
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          this.inputForm.devId = ids
          this.loading = true
          this.$http({
            url: `/info/program/jfInfoTask/treeData`,
            method: 'get'
          }).then(({data}) => {
            this.options = data.treeData || []
            this.loading = false
          })
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/cmd/jfCmd/issueTask`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.$message.success(data.msg)
                this.visible = false
                this.$emit('issueTaskStart', data.list)
                // 下发成功后，把数据丢给父页面进行定时查看下载进度
              }
            })
          }
        })
      }
    }
  }
</script>
<style>
 .info-issue .el-row .el-form-item:last-child{
   margin-bottom: 0;
 }
</style>
